﻿using NUnit.Framework;
using Spring.Context;
using Spring.Context.Support;

using System.Collections.Generic;
using OpenSda.Agilcont.Common.Business.Contracts;
using OpenSda.Agilcont.Common.Data.Entities;
using OpenSda.Agilcont.Common.Data.Contracts;
using OpenSda.Agilcont.Common.Business.Exceptions;


namespace OpenSda.Agilcont.Common.Business.SfContexts.NmTest
{
    [TestFixture]
    public class UserBusinessTest : AbstractBaseDataTests
    {

        private IUserBusiness target;
        public  IUserBusiness UserBusiness { set { target = value; } }
        private IAgenciaData agenciaData;
        public IAgenciaData AgenciaData { set { agenciaData = value; } }



        [Test]
        [ExpectedException(typeof(UserCannotBeNullException))]
        public void SaveWhenUserIsNullTest()
        {
            target.Save(null);
        }

       

        [Test]
        public void SaveTest()
        {
            User user = this.Save();
            Assert.IsNotNull(user.Identity);
        }


        private User Save()
        {
            Agencia u = agenciaData.GetAll()[0];

            return target.Save(new User()
            {
               
                Name = "8",
                AgenciaRef=u    });
        }


        [Test]
        public void GetByIdTest()
        {
            User user = this.Save();
            //target.Delete(user);
            User u = target.GetByid(user.Identity);
            Assert.IsNotNull(u.Identity);
        }

        //[Test]
        //public void DeleteTest()
        //{
        //    User user = this.Save();
        //    target.Delete(user);
        //    User u = userData.Select(user.Identity);
        //    Assert.IsNull(u.Identity);
        //}



     

    }
}
